<?php
// @formatter:off
/**
 * @file c.collection.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-16 23:56:49 +0000 (Sun, 16 Jun 2013) $
 *
 * $Id: c.collection.php 73 2013-06-16 23:56:49Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0/themes/mdefault/controlers/contents/c.collection.php $
 */
// @formatter:on

if($wcProfile->allowedTo(WC_PERM_COLLECTION_VIEW)) {
	require_once "{$this->_themeRoot}/controlers/generics/pager.php";

	if($wcCollection && $wcCollection->ok()) {
		global $wcCollectionsHolder;
		global $wcDefaults;
		global $wcReadRate;

		$wcThemeAssigns["PATH"] = "{$wcCollection->name}";
		$wcThemeAssigns["ACTIONCONTENT"] = "/generics/list-view.html";

		$comics = array();
		$collections = array();

		$gid = $wcGroup->id();
		$iconId = 1;
		$zoom = array();

		$items = $wcCollection->comics();
		uasort($items, "WCComic::NameSort");
		foreach($items as $comic) {
			$aux = array(
				"name" => $comic->name,
				"title" => $comic->name,
				"iconid" => $iconId,
				"icon" => $comic->previewUri(),
				"url" => "?action=".WC_ACTION_COMIC_SHOW."&group={$gid}&comic={$comic->id}"
			);
			if($wcProfile->allowedTo(WC_PERM_COMIC_SET_RATE, WC_PERM_COMIC_SET_READ)) {
				$aux["widget"] = "/generics/list-view-comic-widget.html";

				$readRate = $wcReadRate->comicReadRate($comic);
				$aux["w-global-rate"] = $readRate["rate"];

				$readRate = $wcReadRate->readRate($comic);
				$aux["w-rate"] = $readRate["rate"]["rate"] ? $readRate["rate"]["rate"] : 0;
				$light = $readRate["read"]["read"] ? "on" : "off";
				$aux["w-light"] = $wcDefaults["icon-light-{$light}"];
			}
			$comics[] = $aux;

			$zoom[] = array(
				"id" => $iconId,
				"path" => $comic->previewUri()
			);

			$iconId++;
		}

		$ids = 1;
		$items = $wcCollection->collections();
		uasort($items, "WCCollection::Sort");
		foreach($items as $collection) {
			$collections[] = array(
				"name" => $collection->name,
				"title" => $collection->name,
				"iconid" => $iconId,
				"icon" => $collection->preview(),
				"url" => "?action=".WC_ACTION_COLLECTION_SHOW."&group={$gid}&collection={$collection->id}"
			);

			$zoom[] = array(
				"id" => $iconId,
				"path" => $collection->preview()
			);

			$iconId++;
		}

		$comicsCount = count($comics);
		$collectionsCount = count($collections);
		if($comicsCount) {
			$wcThemeAssigns["COMICS"] = $comics;
		}
		if($collectionsCount) {
			$wcThemeAssigns["COLLECTIONS"] = $collections;
		}

		if($wcCollection->ok() && !$wcCollection->valid_preview) {
			$wcCollection->generatePreviews();
		}

		$lists = array();
		if($collectionsCount) {
			$lists[] = array(
				"prefix" => "Sub Collections",
				"list" => $collections
			);
		}
		if($comicsCount) {
			$lists[] = array(
				"prefix" => "Comics",
				"list" => $comics
			);
		}
		if(($collectionsCount + $comicsCount) == 0) {
			$lists[] = array(
				"prefix" => "No available members",
				"list" => array()
			);
		}

		$wcThemeAssigns["MenuLists"] = $lists;
		$wcThemeAssigns["MenuListsZoom"] = $zoom;

		$wcThemeAssigns["MenuListsInfo"] = array(
			array(
				"label" => "Collection",
				"value" => $wcCollection->name
			),
			array(
				"label" => "Comics",
				"value" => $comicsCount
			),
			array(
				"label" => "Collections",
				"value" => $collectionsCount
			)
		);

		if($wcCollection->parent) {
			$parent = $wcCollectionsHolder->item($wcCollection->parent, $wcGroup);
			if($parent && $parent->ok()) {
				$wcThemeAssigns["MenuListsInfo"][] = array(
					"label" => "Parent",
					"value" => $parent->name,
					"url" => "?action=".WC_ACTION_COLLECTION_SHOW."&group={$gid}&collection={$parent->id}"
				);
			}
		}
	} else {
		$wcThemeAssigns["error-string"] = "Invalid collection";
		require "{$this->_themeRoot}/controlers/contents/c.500.php";
	}
} else {
	$wcThemeAssigns["error-string"] = "You're not allowed to open collections";
	require "{$this->_themeRoot}/controlers/contents/c.403.php";
}
?>